import { createApp } from 'vue';
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import locale from 'element-plus/lib/locale/lang/zh-cn';
import App from './App.vue';
//在GoodslistAxios.vue里使用设置的默认host
import axios from 'axios';
import router from './router/index.js';
import NProgress from 'nprogress';
import "nprogress/nprogress.css";

axios.defaults.baseURL=import.meta.env.VITE_APP_URL;
axios.interceptors.request.use((res)=>{
    //可以把token添加放到这，token是在login的时候放入的。看Login.vue
    const token = window.sessionStorage.getItem('token');
    res.headers.Authorization=token;
    NProgress.start();
    return res;
})

axios.interceptors.response.use((res)=>{
    console.log(res.status);
    NProgress.done();
    return res;
},(err)=>{
    NProgress.done();
    ElMessage.error("server error: can not get info from server");
   })
const app = createApp(App);
app.use(ElementPlus,{locale});
app.use(router);
app.mount('#app')
